home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.809 < prev    next >
Text File  |  1992-02-06  |  3KB  |  56 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fswiss Helvetica;}
  2. \paperw12560
  3. \paperh8740
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ul0\fs28\fc0 pop-up list
  8. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340  free memory leak bug workaround\
  9. \
  10. Q:    I created a 
  11. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\fc0 pop-up list
  12. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340  by dragging it from the InterfaceBuilder palette into a window, but it doesn't seem to be freed when the window is freed. \
  13. \
  14. A:  This is a bug.  Freeing a 
  15. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\fc0 window
  16. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340  
  17. \i does
  18. \i0  free all of its views, but the 
  19. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\fc0 pop-up list
  20. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340  is not a member of the view 
  21. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0 hierarchy
  22. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340 !  It's attached as the target of a Button.   There are two situations in which this bug can bite an unwary programmer:\
  23. \
  24.     1) An application creates multiple document windows by loading a nib section multiple times.  In the nib section, there's a 
  25. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\fc0 window
  26. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340  containing a 
  27. \fc0 pop-up list
  28. .  The application leaks a 
  29. pop-up list
  30.  instance and a DPS window each time a document is closed.  Furthermore, MallocDebug's "Leaks" button won't find the missing nodes because a 
  31. pop-up list
  32.  is a 
  33. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\fc0 window
  34. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340 , and there are pointers to the missing 
  35. \fc0 pop-up list
  36. s in [NXApp windowList].\
  37. \
  38.     2) Same situation as in (1), except that each time, the nib section is loaded into a unique zone, and the zones are destroyed when the documents are closed.  Destroying the zone gets rid of all the garbage, but now there are bad pointers in [NXApp windowList].  Some time later, the application crashes in code that you didn't write, referencing objects that you don't know about, leaving you very confused.\
  39. \
  40.     The solution is to free the 
  41. pop-up list
  42.  when you free the 
  43. window
  44. .  When setting up the nib file, make an outlet to the Button.  In your code, use the outlet to ask the Button for its target before you free the 
  45. window
  46. .  The target will be the 
  47. pop-up list
  48. , which you then free explicitly.\
  49.     \
  50. QA809\
  51. \
  52. Valid for 1.0\
  53. Valid for 2.0\
  54. \
  55.  
  56.